package businesslogic.coursebl;

import java.rmi.ConnectException;
import java.rmi.RemoteException;
import java.util.ArrayList;

import vo.CourseVO;
import vo.UserVO;
import businesslogicservice.courseblservice.courseblservice;

public class CourseController implements courseblservice {
	CourseListController courseListController = new CourseListController();
	CourseInfoController courseInfoController = new CourseInfoController();
	CourseScoreController courseScoreController = new CourseScoreController();

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#getAllCourseList
	 * (java.lang.String, java.lang.String, java.lang.String, int)
	 */
	public ArrayList<CourseVO> getAllCourseList(String type, String semester,
			String department, int grade) throws ConnectException {
		ArrayList<CourseVO> toReturn = null;
		try {
			toReturn = courseListController.getAllCourseList(type, semester,
					department, grade);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#getMyCourseList(
	 * vo.UserVO, java.lang.String)
	 */
	public ArrayList<CourseVO> getMyCourseList(UserVO user, String term)
			throws ConnectException {
		ArrayList<CourseVO> toReturn = null;
		try {
			toReturn = courseListController.getMyCourseList(user, term);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#getCourseListByTeacher
	 * (vo.UserVO)
	 */
	public ArrayList<CourseVO> getCourseListByTeacher(UserVO user)
			throws ConnectException {
		ArrayList<CourseVO> toReturn = null;
		try {
			toReturn = courseListController.getCourseListByTeacher(user);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#getSelectedCourseList
	 * (vo.UserVO, java.lang.String)
	 */
	public ArrayList<CourseVO> getSelectedCourseList(UserVO user, String type)
			throws ConnectException {
		ArrayList<CourseVO> toReturn = null;
		try {
			toReturn = courseListController.getSelectedCourseList(user, type);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#getSelectList(java
	 * .lang.String, vo.UserVO)
	 */
	public ArrayList<CourseVO> getSelectList(String type, UserVO user)
			throws ConnectException {
		ArrayList<CourseVO> toReturn = null;
		try {
			toReturn = courseListController.getSelectList(type, user);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#getCourseByDepartment
	 * (java.lang.String)
	 */
	public ArrayList<CourseVO> getCourseByDepartment(String department)
			throws ConnectException {
		ArrayList<CourseVO> toReturn = null;
		try {
			toReturn = courseListController.getCourseByDepartment(department);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#getCourseByType(
	 * java.lang.String)
	 */
	public ArrayList<CourseVO> getCourseByType(String type)
			throws ConnectException {
		ArrayList<CourseVO> toReturn = null;
		try {
			toReturn = courseListController.getCourseByType(type);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#quitCourse(vo.UserVO
	 * , java.lang.String)
	 */
	public String quitCourse(UserVO user, String courseId)
			throws ConnectException {
		String toReturn = null;
		try {
			toReturn = courseInfoController.quitCourse(user, courseId);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#selectCourse(vo.
	 * UserVO, java.lang.String)
	 */
	public String selectCourse(UserVO user, String courseId)
			throws ConnectException {
		String toReturn = null;
		try {
			toReturn = courseInfoController.selectCourse(user, courseId);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#quitWaitingCourse
	 * (vo.UserVO, java.lang.String)
	 */
	public boolean quitWaitingCourse(UserVO user, String courseId)
			throws ConnectException {
		boolean toReturn = false;
		try {
			toReturn = courseInfoController.quitWaitingCourse(user, courseId);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#selectWaitingCourse
	 * (vo.UserVO, java.lang.String)
	 */
	public String selectWaitingCourse(UserVO user, String courseId)
			throws ConnectException {
		String toReturn = null;
		try {
			toReturn = courseInfoController.selectWaitingCourse(user, courseId);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#addCourse(vo.CourseVO
	 * )
	 */
	public boolean addCourse(CourseVO vo) throws ConnectException {
		boolean toReturn = false;
		try {
			toReturn = courseInfoController.addCourse(vo);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#updateCourse(vo.
	 * CourseVO)
	 */
	public boolean updateCourse(CourseVO vo) throws ConnectException {
		boolean toReturn = false;
		try {
			toReturn = courseInfoController.updateCourse(vo);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#recordScore(vo.CourseVO
	 * )
	 */
	public boolean recordScore(CourseVO vo) throws ConnectException {
		boolean toReturn = false;
		try {
			toReturn = courseScoreController.recordScore(vo);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#getStateOfCourse
	 * (java.lang.String)
	 */
	public int getStateOfCourse(String type) throws ConnectException {
		int toReturn = -1;
		try {
			toReturn = courseInfoController.getStateOfCourse(type);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return toReturn;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * businesslogicservice.courseblservice.courseblservice#setStateOfCourse
	 * (java.lang.String, int)
	 */
	public void setStateOfCourse(String type, int state)
			throws ConnectException {
		try {
			courseInfoController.setStateOfCourse(type, state);
		} catch (ConnectException e) {
			throw e;
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}
}
